<?php
/*权限管理*/
namespace Admin\Controller;
use Think\Page;//分页类

class MatchlistController extends BaseController {

    public function list_(){
        #+----------------------------------
        # * 查询权限
        #+----------------------------------
        $qx_list = M()->query("select * from adminrule group by ac order by id desc");
        
        foreach ($qx_list as $k => $v) {
            $ac = $qx_list[$k]['ac'];
            $data = M()->query("select * from adminrule where ac = '$ac'");
            $qx_list[$k]['data'] = $data;
            //查询权限
        }
        $this -> assign( "qx_list", $qx_list); 
        // print_r($qx_list);
    	#+----------------------------------
    	# * 分页
    	#+----------------------------------
        $db = M( "admingroup" );  
        $page_size = 10; //每页显示记录数  
        $record_sum = count( $db -> field('id') -> where( "1=1" ) -> select() );//记录总数  
		$Page = new Page($record_sum, $page_size);  //实例化分页类
        $list = $db-> 
                /*field( "adminuser.id,adminuser.username,groupname,logintime" ) ->  
                join( "admingroup on adminuser.group_id=admingroup.id" ) ->  */
                where( "" ) ->  
                // order( "adminuser.id " ) ->  
                limit($Page->firstRow.",".$Page->listRows) ->  
                select();  
        

        $this -> assign( "list", $list); //输出文章列表  
        $this -> assign( "page", $Page -> show_wen()); //输出分页  
        #+----------------------------------
        # * 显示页面
        #+----------------------------------
    	$this->display();
    }
    public function add_edit(){
        // print_r($_GET);exit;
        $arr = $_GET;
        $id = $_GET['id'];
        $type = $_GET['type'];
        $arr['rule_str'] = '';
        foreach ($_GET['qx'] as $k => $v) {
            $arr['rule_str'] .= $k.',';
        }
        $arr['rule_str'] = trim($arr['rule_str'],',');
        // print_r($arr);exit;

        unset($arr['id']);
        unset($arr['type']);
        unset($arr['qx']);

        if($type == '1'){//添加
            $re = M('admingroup')->add($arr);
            if($re){
                echojson('添加成功',1);
            }else{
                echojson('添加失败',0);
            }
        }elseif($type == '2'){//修改
            
            $re = M('admingroup')->where("id=$id")->save($arr);
            if($re){
                echojson('修改成功',1);
            }else{
                echojson('修改失败',0);
            }
        }
    }
}